﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MotorcycleStore.Repository;

namespace MotorcycleStore.MVC.Controllers
{
	[HandleError]
	public class HomeController : Controller
	{
		private IMotorcycleRepository repository;

		public HomeController(IMotorcycleRepository repository)
		{
			this.repository = repository;
		}

		public ActionResult Index()
		{
			ViewData["Message"] = "Welcome to ASP.NET MVC!";

			return View();
		}

		public ViewResult Manufacturer(string name)
		{
			var manufacturer = repository.Manufacturers.SingleOrDefault(m => m.Name == name);

			if(manufacturer != null)
				return View(manufacturer);

			return View("NotFound");
		}

		public ActionResult About()
		{
			return View();
		}
	}
}
